package us.icitap.cm.business.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;

import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.business.entities.regmin.States;
import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="PERSON", schema="MPC")
public class Person implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1681875633362690922L;


	@Id
	@Column(insertable=false, updatable = false)
	private Integer id;
	

	@OneToOne
	@JoinColumn(name="ID",nullable=false)
	private AppEntity appEntity;

	@Column(length=30)
	private String name;
	
	@Column(length=30)
	private String surname;
	
	@Column(length=30, name="FATHER_NAME")
	private String fatherName;
	
	@Column(length=30, name="MOTHER_NAME")
	private String motherName;
	

	@Enumerated(EnumType.STRING)
	private SexEnum sex;
	
	
	
	@Temporal(TemporalType.DATE)
	@Column(name="BIRTH_DATE")
	private Date birthDate;
	
	private Integer age;


	@ManyToOne
	@JoinColumn(name="NATIONALITY_ID")
	private States nationality;
	
	@ManyToOne
	@JoinColumn(name="EDUCATION_ID")
	private AppList education;
	
	@ManyToOne
	@JoinColumn(name="PROFESSION_ID")
	private AppList profession;
	

	@ManyToOne
	@JoinColumn(name="SPECIAL_QUALITY_ID")
	private AppList specialQuality;
	
	@Column(name = "CEL_NO", length=15)
	private String celNo;
	
	@Column(name = "PHONE_NO", length=15)
	private String phoneNo;
	
	@Column(name = "LAWYER", length=60)
	private String lawyer;
	
	@Column(name = "LAWYER_CEL_NO", length=15)
	private String lawyerCelNo;
	
	@Column(name = "LAWYER_PHONE_NO", length=15)
	private String lawyerPhoneNo;
	
	
	private Double height;
	
	private Double weight;
	
	@OneToMany(mappedBy="person", fetch=FetchType.EAGER)
	private List<Alias> aliasList;
	
	
	@Column(name="ALCOHOL_INFLUENCE")
	private boolean alcoholInfluence;
	
	@Column(name="ALCO_INFL_OVER_LIMIT")
	private boolean alcoInflOverLimit;
	
	@Column(name="DRUGS_INFLUENCE")
	private boolean drugsInfluence;
	
	@Column(name="OTHER_INFLUENCE")
	private String otherInfluence;
	
	
	
	
	@ManyToOne
	@JoinColumn(name="HUMAN_RACE_ID")
	private AppList humanRace;
	
	@ManyToOne
	@JoinColumn(name="EYE_COLOR_ID")
	private AppList eyeColor;
	
	@ManyToOne
	@JoinColumn(name="HAIR_COLOR_ID")
	private AppList hairColor;
	
	
	
	@ManyToOne
	@JoinColumn(name="PHYS_PSY_STATUS_ID")
	private AppList physicalPsychicStatus;
	
	@ManyToOne
	@JoinColumn(name="ACTUAL_SITUATION_ID")
	private ActualSituation actualSituation;
	
	@ManyToOne
	@JoinColumn(name="PERSON_STATUS_ID")
	private AppList personStatus;
	
	@ManyToOne
	@JoinColumn(name="INVOLVEMENT_ID")
	private AppList involvement;
	
	@ManyToOne
	@JoinColumn(name="FILE_TYPE_ID")
	private AppList fileType;
	
	
	
	
	public Person(){
		
	}
	
	public Person(Person person){
		this.name = person.getName();
		this.surname = person.getSurname();
		this.actualSituation = person.getActualSituation();
		this.age = person.getAge();
		this.alcoholInfluence = person.isAlcoholInfluence();
		this.alcoInflOverLimit = person.isAlcoInflOverLimit();
		this.birthDate = person.getBirthDate();
		this.celNo = person.getCelNo();
		this.drugsInfluence = person.isDrugsInfluence();
		this.education = person.getEducation();
		this.eyeColor = person.getEyeColor();
		this.fatherName = person.getFatherName();
		this.hairColor = person.getHairColor();
		this.height = person.getHeight();
		this.humanRace = person.getHumanRace();
		this.lawyer = person.getLawyer();
		this.lawyerCelNo = person.getLawyerCelNo();
		this.lawyerPhoneNo = person.getLawyerPhoneNo();
		this.motherName = person.getMotherName();
		this.nationality = person.getNationality();
		this.otherInfluence = person.getOtherInfluence();
		this.personStatus = person.getPersonStatus();
		this.phoneNo = person.getPhoneNo();
		this.physicalPsychicStatus = person.getPhysicalPsychicStatus();
		this.profession = person.getProfession();
		this.sex = person.getSex();
		this.specialQuality = person.getSpecialQuality();
		this.surname = person.getSurname();
		this.weight = person.getWeight();
		this.involvement = person.getInvolvement();
		this.fileType = person.getFileType();
		
		
		
		if(person.getAliasList() != null){
			aliasList = new ArrayList<Alias>();
			for (Alias alias : person.getAliasList()) {
				Alias newAlias = new Alias();
				newAlias.setAlias(alias.getAlias());
				newAlias.setId(alias.getId());
				newAlias.setPerson(this);
				aliasList.add(newAlias);
			}
		}
	
	}
	

	public Double getHeight() {
		return height;
	}

	public void setHeight(Double height) {
		this.height = height;
	}

	public Double getWeight() {
		return weight;
	}

	public void setWeight(Double weight) {
		this.weight = weight;
	}

	

	public List<Alias> getAliasList() {
		return aliasList;
	}

	public void setAliasList(List<Alias> aliasList) {
		this.aliasList = aliasList;
	}

	

	public AppList getPersonStatus() {
		return personStatus;
	}

	public void setPersonStatus(AppList personStatus) {
		this.personStatus = personStatus;
	}

	public boolean isAlcoholInfluence() {
		return alcoholInfluence;
	}

	public void setAlcoholInfluence(boolean alcoholInfluence) {
		this.alcoholInfluence = alcoholInfluence;
	}

	public boolean isAlcoInflOverLimit() {
		return alcoInflOverLimit;
	}

	public void setAlcoInflOverLimit(boolean alcoInflOverLimit) {
		this.alcoInflOverLimit = alcoInflOverLimit;
	}

	public boolean isDrugsInfluence() {
		return drugsInfluence;
	}

	public void setDrugsInfluence(boolean drugsInfluence) {
		this.drugsInfluence = drugsInfluence;
	}

	public String getOtherInfluence() {
		return otherInfluence;
	}

	public void setOtherInfluence(String otherInfluence) {
		this.otherInfluence = otherInfluence;
	}



	public AppList getHumanRace() {
		return humanRace;
	}

	public void setHumanRace(AppList humanRace) {
		this.humanRace = humanRace;
	}

	public AppList getEyeColor() {
		return eyeColor;
	}

	public void setEyeColor(AppList eyeColor) {
		this.eyeColor = eyeColor;
	}

	public AppList getHairColor() {
		return hairColor;
	}

	public void setHairColor(AppList hairColor) {
		this.hairColor = hairColor;
	}

	
	public AppList getPhysicalPsychicStatus() {
		return physicalPsychicStatus;
	}

	public void setPhysicalPsychicStatus(AppList physicalPsychicStatus) {
		this.physicalPsychicStatus = physicalPsychicStatus;
	}

	public ActualSituation getActualSituation() {
		return actualSituation;
	}

	public void setActualSituation(ActualSituation actualSituation) {
		this.actualSituation = actualSituation;
	}

	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public AppEntity getAppEntity() {
		return appEntity;
	}

	public void setAppEntity(AppEntity appEntity) {
		this.appEntity = appEntity;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public SexEnum getSex() {
		return sex;
	}

	public void setSex(SexEnum sex) {
		this.sex = sex;
	}
	
	public String getFatherName() {
		return fatherName;
	}

	public void setFatherName(String fatherName) {
		this.fatherName = fatherName;
	}

	public String getMotherName() {
		return motherName;
	}

	public void setMotherName(String motherName) {
		this.motherName = motherName;
	}
	
	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}
	
	public States getNationality() {
		return nationality;
	}

	public void setNationality(States nationality) {
		this.nationality = nationality;
	}
	
	public AppList getEducation() {
		return education;
	}

	public void setEducation(AppList education) {
		this.education = education;
	}

	public AppList getProfession() {
		return profession;
	}

	public void setProfession(AppList profession) {
		this.profession = profession;
	}

	public AppList getSpecialQuality() {
		return specialQuality;
	}

	public void setSpecialQuality(AppList
			specialQuality) {
		this.specialQuality = specialQuality;
	}

	
	@Override
	public String toString() {
		if(this.name != null|| this.surname != null) 
			return name + " " + surname;
		else 
			return "Personi nr." + id ;
	}

	public String getCelNo() {
		return celNo;
	}

	public void setCelNo(String celNo) {
		this.celNo = celNo;
	}

	public String getPhoneNo() {
		return phoneNo;
	}

	public void setPhoneNo(String phoneNo) {
		this.phoneNo = phoneNo;
	}

	public String getLawyer() {
		return lawyer;
	}

	public void setLawyer(String lawyer) {
		this.lawyer = lawyer;
	}

	public String getLawyerCelNo() {
		return lawyerCelNo;
	}

	public void setLawyerCelNo(String lawyerCelNo) {
		this.lawyerCelNo = lawyerCelNo;
	}

	public String getLawyerPhoneNo() {
		return lawyerPhoneNo;
	}

	public void setLawyerPhoneNo(String lawyerPhoneNo) {
		this.lawyerPhoneNo = lawyerPhoneNo;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((actualSituation == null) ? 0 : actualSituation.hashCode());
		result = prime * result + ((age == null) ? 0 : age.hashCode());
		result = prime * result + (alcoInflOverLimit ? 1231 : 1237);
		result = prime * result + (alcoholInfluence ? 1231 : 1237);
		result = prime * result
				+ ((aliasList == null) ? 0 : aliasList.hashCode());
		result = prime * result
				+ ((birthDate == null) ? 0 : birthDate.hashCode());
		result = prime * result + ((celNo == null) ? 0 : celNo.hashCode());
		result = prime * result + (drugsInfluence ? 1231 : 1237);
		result = prime * result
				+ ((education == null) ? 0 : education.hashCode());
		result = prime * result
				+ ((eyeColor == null) ? 0 : eyeColor.hashCode());
		result = prime * result
				+ ((fatherName == null) ? 0 : fatherName.hashCode());
		result = prime * result
				+ ((hairColor == null) ? 0 : hairColor.hashCode());
		result = prime * result + ((height == null) ? 0 : height.hashCode());
		result = prime * result
				+ ((humanRace == null) ? 0 : humanRace.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((lawyer == null) ? 0 : lawyer.hashCode());
		result = prime * result
				+ ((lawyerCelNo == null) ? 0 : lawyerCelNo.hashCode());
		result = prime * result
				+ ((lawyerPhoneNo == null) ? 0 : lawyerPhoneNo.hashCode());
		result = prime * result
				+ ((motherName == null) ? 0 : motherName.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((nationality == null) ? 0 : nationality.hashCode());
		result = prime * result
				+ ((otherInfluence == null) ? 0 : otherInfluence.hashCode());
		result = prime * result
				+ ((personStatus == null) ? 0 : personStatus.hashCode());
		result = prime * result + ((phoneNo == null) ? 0 : phoneNo.hashCode());
		result = prime
				* result
				+ ((physicalPsychicStatus == null) ? 0 : physicalPsychicStatus
						.hashCode());
		result = prime * result
				+ ((profession == null) ? 0 : profession.hashCode());
		result = prime * result + ((sex == null) ? 0 : sex.hashCode());
		result = prime * result
				+ ((specialQuality == null) ? 0 : specialQuality.hashCode());
		result = prime * result + ((surname == null) ? 0 : surname.hashCode());
		result = prime * result + ((weight == null) ? 0 : weight.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (actualSituation == null) {
			if (other.actualSituation != null)
				return false;
		} else if (!actualSituation.equals(other.actualSituation))
			return false;
		if (age == null) {
			if (other.age != null)
				return false;
		} else if (!age.equals(other.age))
			return false;
		if (alcoInflOverLimit != other.alcoInflOverLimit)
			return false;
		if (alcoholInfluence != other.alcoholInfluence)
			return false;
		if (aliasList == null) {
			if (other.aliasList != null)
				return false;
		} else if (!aliasList.equals(other.aliasList))
			return false;
		if (birthDate == null) {
			if (other.birthDate != null)
				return false;
		} else if (!birthDate.equals(other.birthDate))
			return false;
		if (celNo == null) {
			if (other.celNo != null)
				return false;
		} else if (!celNo.equals(other.celNo))
			return false;
		if (drugsInfluence != other.drugsInfluence)
			return false;
		if (education == null) {
			if (other.education != null)
				return false;
		} else if (!education.equals(other.education))
			return false;
		if (eyeColor == null) {
			if (other.eyeColor != null)
				return false;
		} else if (!eyeColor.equals(other.eyeColor))
			return false;
		if (fatherName == null) {
			if (other.fatherName != null)
				return false;
		} else if (!fatherName.equals(other.fatherName))
			return false;
		if (hairColor == null) {
			if (other.hairColor != null)
				return false;
		} else if (!hairColor.equals(other.hairColor))
			return false;
		if (height == null) {
			if (other.height != null)
				return false;
		} else if (!height.equals(other.height))
			return false;
		if (humanRace == null) {
			if (other.humanRace != null)
				return false;
		} else if (!humanRace.equals(other.humanRace))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (lawyer == null) {
			if (other.lawyer != null)
				return false;
		} else if (!lawyer.equals(other.lawyer))
			return false;
		if (lawyerCelNo == null) {
			if (other.lawyerCelNo != null)
				return false;
		} else if (!lawyerCelNo.equals(other.lawyerCelNo))
			return false;
		if (lawyerPhoneNo == null) {
			if (other.lawyerPhoneNo != null)
				return false;
		} else if (!lawyerPhoneNo.equals(other.lawyerPhoneNo))
			return false;
		if (motherName == null) {
			if (other.motherName != null)
				return false;
		} else if (!motherName.equals(other.motherName))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (nationality == null) {
			if (other.nationality != null)
				return false;
		} else if (!nationality.equals(other.nationality))
			return false;
		if (otherInfluence == null) {
			if (other.otherInfluence != null)
				return false;
		} else if (!otherInfluence.equals(other.otherInfluence))
			return false;
		if (personStatus != other.personStatus)
			return false;
		if (phoneNo == null) {
			if (other.phoneNo != null)
				return false;
		} else if (!phoneNo.equals(other.phoneNo))
			return false;
		if (physicalPsychicStatus == null) {
			if (other.physicalPsychicStatus != null)
				return false;
		} else if (!physicalPsychicStatus.equals(other.physicalPsychicStatus))
			return false;
		if (profession == null) {
			if (other.profession != null)
				return false;
		} else if (!profession.equals(other.profession))
			return false;
		if (sex != other.sex)
			return false;
		if (specialQuality == null) {
			if (other.specialQuality != null)
				return false;
		} else if (!specialQuality.equals(other.specialQuality))
			return false;
		if (surname == null) {
			if (other.surname != null)
				return false;
		} else if (!surname.equals(other.surname))
			return false;
		if (weight == null) {
			if (other.weight != null)
				return false;
		} else if (!weight.equals(other.weight))
			return false;
		return true;
	}
	
	public boolean myEquals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (actualSituation == null) {
			if (other.actualSituation != null)
				return false;
		} else if (!actualSituation.equals(other.actualSituation))
			return false;
		if (age == null) {
			if (other.age != null)
				return false;
		} else if (!age.equals(other.age))
			return false;
		if (alcoInflOverLimit != other.alcoInflOverLimit)
			return false;
		if (alcoholInfluence != other.alcoholInfluence)
			return false;
		if (aliasList == null) {
			if (other.aliasList != null)
				return false;
		} else if (!aliasList.equals(other.aliasList))
			return false;
		if (birthDate == null) {
			if (other.birthDate != null)
				return false;
		} else if (!birthDate.equals(other.birthDate))
			return false;
		if (celNo == null) {
			if (other.celNo != null)
				return false;
		} else if (!celNo.equals(other.celNo))
			return false;
		if (drugsInfluence != other.drugsInfluence)
			return false;
		if (education == null) {
			if (other.education != null)
				return false;
		} else if (!education.equals(other.education))
			return false;
		if (eyeColor == null) {
			if (other.eyeColor != null)
				return false;
		} else if (!eyeColor.equals(other.eyeColor))
			return false;
		if (fatherName == null) {
			if (other.fatherName != null)
				return false;
		} else if (!fatherName.equals(other.fatherName))
			return false;
		if (hairColor == null) {
			if (other.hairColor != null)
				return false;
		} else if (!hairColor.equals(other.hairColor))
			return false;
		if (height == null) {
			if (other.height != null)
				return false;
		} else if (!height.equals(other.height))
			return false;
		if (humanRace == null) {
			if (other.humanRace != null)
				return false;
		} else if (!humanRace.equals(other.humanRace))
			return false;
		
		if (lawyer == null) {
			if (other.lawyer != null)
				return false;
		} else if (!lawyer.equals(other.lawyer))
			return false;
		if (lawyerCelNo == null) {
			if (other.lawyerCelNo != null)
				return false;
		} else if (!lawyerCelNo.equals(other.lawyerCelNo))
			return false;
		if (lawyerPhoneNo == null) {
			if (other.lawyerPhoneNo != null)
				return false;
		} else if (!lawyerPhoneNo.equals(other.lawyerPhoneNo))
			return false;
		if (motherName == null) {
			if (other.motherName != null)
				return false;
		} else if (!motherName.equals(other.motherName))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (nationality == null) {
			if (other.nationality != null)
				return false;
		} else if (!nationality.equals(other.nationality))
			return false;
		if (otherInfluence == null) {
			if (other.otherInfluence != null)
				return false;
		} else if (!otherInfluence.equals(other.otherInfluence))
			return false;
		if (personStatus != other.personStatus)
			return false;
		if (phoneNo == null) {
			if (other.phoneNo != null)
				return false;
		} else if (!phoneNo.equals(other.phoneNo))
			return false;
		if (physicalPsychicStatus == null) {
			if (other.physicalPsychicStatus != null)
				return false;
		} else if (!physicalPsychicStatus.equals(other.physicalPsychicStatus))
			return false;
		if (profession == null) {
			if (other.profession != null)
				return false;
		} else if (!profession.equals(other.profession))
			return false;
		if (sex != other.sex)
			return false;
		if (specialQuality == null) {
			if (other.specialQuality != null)
				return false;
		} else if (!specialQuality.equals(other.specialQuality))
			return false;
		if (surname == null) {
			if (other.surname != null)
				return false;
		} else if (!surname.equals(other.surname))
			return false;
		if (weight == null) {
			if (other.weight != null)
				return false;
		} else if (!weight.equals(other.weight))
			return false;
		return true;
	}

	public AppList getInvolvement() {
		return involvement;
	}

	public void setInvolvement(AppList involvement) {
		this.involvement = involvement;
	}

	public AppList getFileType() {
		return fileType;
	}

	public void setFileType(AppList fileType) {
		this.fileType = fileType;
	}





}
